package com.mjlf.boot.thrift.idl.impl;

import com.mjlf.boot.thrift.idl.DataException;
import com.mjlf.boot.thrift.idl.EventData;
import com.mjlf.boot.thrift.idl.EventService;
import org.apache.thrift.TException;

import java.awt.*;

/**
 * @ClassName EventServiceImpl
 * @Author mjlft
 * @Date 2020/3/6 15:30
 * @Version 1.0
 * @Description TODO
 */
public class EventServiceImpl implements EventService.Iface {
    public void doEvent(EventData eventData) throws DataException, TException {
        try {
            Robot robot = new Robot();
            // 执行完一个事件后再执行下一个
            robot.setAutoWaitForIdle(true);
            switch (eventData.eventType){
                case MOUSE_PRESS:
                    robot.mousePress(eventData.getMouseButtons());
                    break;
                case MOUSE_RELEASE:
                    robot.mouseRelease(eventData.getMouseButtons());
                    break;
                case MOUSE_MOVE:
                    robot.mouseMove(eventData.getPointX(), eventData.getPointY());
                    break;
                case MOUSE_DRAG:
//                    robot.mo(eventData.getPointX(), eventData.getPointY());
                    break;
                case MOUSE_WHEEL:
                    robot.mouseWheel(eventData.getWheelNum());
                    break;
                case KEY_PRESS:
                    robot.keyPress(eventData.getKeyCode());
                    break;
                case KEY_RELEASE:
                    robot.keyRelease(eventData.getKeyCode());
                    break;
            }
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
}
